<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title></title>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			#red{
				width: 400px;
				height: 400px;
				background: red;
				margin: 50px;
			}
			#blue{
				width: 250px;
				height: 250px;
				background: blue;
				margin: 30px;
			}
			#yellow{
				width: 100px;
				height: 100px;
				background: yellow;
				margin: 20px;
			}
		</style>
		<script type="text/javascript">
			window.onload = function(){
				var red = document.getElementById("red");
				var blue = document.getElementById("blue");
				var yellow = document.getElementById("yellow");
				//如果是没有定位的元素，参照与离他最近的有定位属性的元素来获得结果
				var res = yellow.offsetLeft;
				alert(res);
			}
		</script>
	</head>
	<body>
		<div id="red">
			<div id="blue">
				<div id="yellow">
					
				</div>
			</div>
		</div>
	</body>
</html>
